import allure
import pymysql

#执行sql
@allure.step("执行sql")
def clientDataBase(sql):
    # 打开数据库连接
    db = pymysql.connect(
        host='10.150.31.106',
        user='root',
        password='123456',
        database='huogui_db',
        charset='utf8')
    # 使用cursor()方法获取操作游标
    cursor = db.cursor()
    try:
        # 执行sql语句
        cursor.execute(sql)
        db.commit()
        data = cursor.fetchall()
    except:
        print("查询失败")
        # 如果发生错误则回滚
        db.rollback()
    finally:
        # 关闭数据库连接
        print('关闭链接')
        db.close()
        return data


